package com.example.mq1.demo;

import com.example.mq1.common.MqException;
import com.example.mq1.mqclient.Channel;
import com.example.mq1.mqclient.Connection;
import com.example.mq1.mqclient.ConnectionFactory;
import com.example.mq1.mqserver.core.BasicProperties;

import java.io.IOException;

public class Consumer {

    public static void main(String[] args) throws IOException, MqException, InterruptedException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(9090);
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        channel.basicConsume("consumerTag1", "testQueue", true, new com.example.mq1.common.Consumer() {
            @Override
            public void handlerDelivery(String consumerTag, BasicProperties basicProperties, byte[] body) throws IOException, MqException {
                System.out.println("开始消费");
                System.out.println("content=" + new String(body));
                System.out.println("结束消费");
            }
        });

        while(true) {
            Thread.sleep(500);
        }

    }

}

